#!/usr/bin/python
# -*- coding: UTF-8 -*-
import psutil
import time
def getProcessInfo(pid):
    # try:
    p=psutil.Process(pid)   
    cpu = int(p.get_cpu_percent(interval=1))
    print cpu
    rss, vms = p.get_memory_info()
    name = p.name
    pid = p.pid
    # except Exception as e:
    #     name = "Closed_Process"
    #     pid = 0
    #     rss = 0
    #     vms = 0
    #     cpu = 0
    return [name.upper(), pid, rss, vms, cpu]
  
def getAllProcessInfo():
    instances = []
    all_processes = list(psutil.process_iter())
    for proc in all_processes:
        proc.get_cpu_percent(interval=0)
    time.sleep(1)
    for proc in all_processes:
        instances.append(getProcessInfo(proc))
    return instances

if __name__ == "__main__":
    res = getAllProcessInfo()
    print res
    # p1=psutil.Process(14733)
    # print p1.get_cpu_percent(interval=0)
